package com.example.zg.zg_312_ordering_new.fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zg.zg_312_ordering_new.R;
import com.example.zg.zg_312_ordering_new.adapter.ShopAdapter;
import com.example.zg.zg_312_ordering_new.beans.Shop;
import com.example.zg.zg_312_ordering_new.listener.RetrofitListener;
import com.example.zg.zg_312_ordering_new.model.ShopModel;
import com.example.zg.zg_312_ordering_new.services.ShopService;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

import java.io.IOException;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;


public class HomeFragment extends BaseFragment implements RetrofitListener<List<Shop>> {
    private RecyclerView recyclerView;
    private ShopAdapter adapter;
   // Context context;
  //  private List<Shop> list;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
       setLayout_file(R.layout.tab01);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

    public void initViews(){
//        context = getContext();
//        adapter = new ShopAdapter();
        recyclerView=(RecyclerView)view.findViewById(R.id.shop_list);
        recyclerView.setAdapter(adapter);
        recyclerView.setHasFixedSize(true);    //提高item性能
        recyclerView.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    }
    void initData(){
        ShopModel shopModel=new ShopModel();
        shopModel.getAllShops(this);
    }

    @Override
    public void onSuccess(List <Shop> shops, int flag) {
        adapter=new ShopAdapter(getActivity(),shops);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail() {
    Toast.makeText(getContext(),"网络连接失败",Toast.LENGTH_LONG).show();
    }

    void initEvents(){

    }
}
